<?php

namespace Modules\Agent\Http\Controllers\Admin\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
// use \Modules\Agent\Entities\AgentRecord;

use Validator;
use ThrowException;
use Auth;
use Setting;

class SettingController extends Controller
{
    public function getBrokerage(Request $req)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $defaultSetting = [
            'is_enabled' => 0
        ];

        $setting = Setting::get('agent_brokerage') ?: [
            [
                'node_type' => 'product',
                'node_type_text' => '普通商品',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'box',
                'node_type_text' => '盲盒',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'fudai',
                'node_type_text' => '福袋',
                'is_enabled' => 0
            ],
            [
                'node_type' => 'yifanshang',
                'node_type_text' => '一番赏',
                'is_enabled' => 0
            ]
        ];

        return [
        	'list' => $setting
        ];
    }

    public function setBrokerage(Request $req)
    {
        $rule = [
            'list' => ['required', 'array']
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $setting = $req->input('list');

        Setting::set('agent_brokerage', $setting);

        return [
        ];
    }
}
